package graphics.raytracing;

import util.MatrixOperationsF;
import graphics.rasterizing.camera.CameraPosition;

public class RayTracer {
	int _xmax;
	int _ymax;
	Model _model;
	CameraPosition camera;
	Window window;
	private int[][] _buffer;
	public RayTracer(Model model,Window window,CameraPosition camera)
	{
		_model =model;
		_xmax=window.xy()[0];
		_ymax=window.xy()[1];
		this.camera=camera;
		this.window=window;
		_buffer=new int[_xmax][_ymax];
	}
	public int[][] traceRays()
	{
		
		for(int i =0;i<_xmax;i++)
			for(int j = 0; j<_ymax;j++)
				window.determineRay(camera, i, j).castOn(_model,window);
		for(int i =0;i<_xmax;i++)
			for(int j = 0; j<_ymax;j++)
				_buffer[i][j]=MatrixOperationsF.tocolor(window.getColor(i, j));
		return _buffer;
	}
}
